package com.example.scan.util;

import org.apache.commons.lang3.StringUtils;

public class StringUtil {

    /**
     * 驼峰字段转下划线字段
     *
     * @param param
     * @return
     */
    public static String camelToUnderline(String param) {
        StringBuilder sb = new StringBuilder();
        param.chars().forEach(value -> {
            if (Character.isUpperCase(value)) {
                sb.append("_");
                sb.append((char) Character.toLowerCase(value));
            } else {
                sb.append((char) value);
            }
        });
        return sb.toString();
    }

    /**
     * 下划线字段转驼峰字段
     *
     * @param param
     * @return
     */
    public static String underlineToCamel(String param) {
        StringBuilder sb = new StringBuilder();
        for (String s : param.split("_")) {
            sb.append(StringUtils.capitalize(s));
        }
        return StringUtils.uncapitalize(sb.toString());
    }


}
